{layout name="main"/}
<div class="wrapper wrapper-content animated fadeInUp">
    {if condition="$user->user_type!='user'"}
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox">

                <div class="ibox-title">
                    <h5>会员排队</h5>

                </div>
                <div class="ibox-content">
                    <form method="post" action="" class="form-horizontal m-t" id="cz">

                        <div class="form-group">
                            <label class="col-sm-3 control-label">消费会员编号 * </label>
                            <div class="col-sm-5">
                                <input type="text" placeholder="请输入会员编号" class="form-control" name="user_uniid" value="">

                            </div>
                        </div>


                        <div class="form-group">
                            <label class="col-sm-3 control-label">报单币 * </label>
                            <div class="col-sm-5">

                                <div class="input-group m-b"><span class="input-group-addon">&yen;</span>
                                    <input type="text" name='cash_value' class="form-control"> <span class="input-group-addon">.00</span>


                                </div>
                                <span class="help-block m-b-none"><i class="fa fa-info-circle"></i> 当前报单币{$user->line_cash}元</span>

                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">排队次数(重复几次报单)</label>
                            <div class="col-sm-5">
                                <input type="text" placeholder="请输入排队次数" class="form-control" name="times" value="1">

                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-sm-4 col-sm-offset-3">
                                <button class="btn btn-primary" type="button" onclick='add()'>确认排队</button>
                            </div>
                        </div>

                    </form>
                </div>
            </div>
        </div>
    </div>
    {/if}
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox">

                <div class="ibox-title">
                    <h5>公排情况</h5>

                </div>

                <div class="ibox-content">
                    <div class="row m-b-sm m-t-sm">
                        <div class="col-sm-5">
                            {if condition="$linelist"}
                            <select class="form-control" onchange="lineChange()" id="line_name" style="width: 50%">
                                <option value=0>请选择代理商</option>
                                {volist name="linelist" id="line"}
                                <option value={$line->line_id}{if condition="$line->line_id==$line_id"} selected{/if}>{$line->line_name}</option>
                                {/volist}
                            </select>
                            {/if}
                        </div>
                        <div class="col-sm-7">
                            <div class="input-group">
                                <input type="text" placeholder="搜索(消费会员编号,消费会员昵称)" class="input-sm form-control" name="keyword" value="{$keyword}"> <span class="input-group-btn">
                                    <button type="button" class="btn btn-sm btn-primary" onclick="search()">搜索</button> </span>
                            </div>
                        </div>
                    </div>
                    <div class="project-list">
                        <table class=" table table-striped table-bordered table-hover dataTables-example dataTable" id="DataTables_Table_0" aria-describedby="DataTables_Table_0_info">
                            <thead>
                                <tr role="row">
                                    <th colspan="8" style=" text-align: center; font-weight: normal; color: green">
                                        目前总排队数：{$countall} &nbsp;&nbsp;&nbsp;&nbsp; 出局数：{$countout}
                                    </th>
                                </tr>
                                <tr role="row">

                                    <th style="width: 10%; text-align: center;">排劵编号</th>
                                    <th style="width: 5%;text-align: center;">公排排名</th>
                                    <th style="width: 10%;text-align: center;">代理商名称</th>
                                    <th style="width: 10%;text-align: center;">消费者账号</th>
                                    <th style="width: 5%;text-align: center;">消费者昵称</th>
                                    <th style="width: 5%;text-align: center;">面值</th>
                                    <th style="width: 10%;text-align: center;">排队时间</th>
                                    <th style="width: 5%;text-align: center;">排队状态</th>
                                </tr>
                            </thead>



                            <tbody>
                              {:table_empty_list($list,'暂无数据!',8)}
                                {volist name="list" id="ticket"}

                                <tr class="gradeA" style=' text-align: center;'>

                                    <td>{$ticket->ticket_id}</td>
                                    <td>{$ticket->rank}</td>
                                    <td class="center ">{$ticket->line->line_name}</td>
                                    <td class="center ">{$ticket->user->user_uniid}</td>
                                    <td class="center ">{$ticket->user->user_name}</td>
                                    <td class="center ">{$ticket->value}</td>
                                    <td class="center">{$ticket->create_time}</td>
                                    <td class="center "><span class="badge {if condition=" $ticket->ticket_status=='已出局'"}badge-primary{else}badge-danger{/if}">{$ticket->ticket_status}</span></td>
                                </tr>
                                {/volist}

                            </tbody>

                        </table>


                        <div class="row">
                            <div class="col-sm-6">
                                <div class="dataTables_info" id="DataTables_Table_0_info" role="alert" aria-live="polite" aria-relevant="all">
                                    每页显示 {:getPageSize()} 项，共 {$list->toArray()['total']} 项</div>
                            </div>
                            <div class="col-sm-6">
                                <div class="dataTables_paginate paging_simple_numbers" id="DataTables_Table_0_paginate">
                                    {$list->render()}

                                </div>

                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <script>
                $(".input-daterange").datepicker({
                    keyboardNavigation: !1,
                    forceParse: !1,
                    autoclose: !0
                });
                //充值
                function add() {

                    var postdata = $("#cz").serialize();
                    post({
                        url: "{:url('/admin/Agent/create_ticket')}",
                        data: postdata,
                        success: function(res) {
                            swal({
                                title: '成功',
                                text: res.message,
                                type: "success"
                            }, function() {
                              reload();
                            });
                        },
                        error: function(error) {
                            swal("错误", JSON.parse(error.responseText).message, "error");
                        }
                    });

                }

                function lineChange() {
                    var line_id = $('#line_name').val();
                    toUrl("{:url('admin/Agent/lineupList',[],'')}/line_id/" + line_id);
                }

                function search() {
                    var keyword = $("input[name=keyword]").val();
                    if (keyword == "" && startdate == "" && enddate == "") {
                        swal("错误", "请输入查询条件", "error");
                        return;
                    }

                    toUrl("{:url('admin/Agent/lineupList', ['line_id'=>$line_id])}/keyword/" + keyword);
                }
            </script>
